package com.sxm.yiwei.adapters;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.beans.FWBook;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.HashMap;
import java.util.List;

/**
 * Created by KuKa on 2017/7/13.
 * 服务 待服务
 */

public class ServiceListAdapter extends BaseAdapter {
    Context context;
   public  List<FWBook.DataBean> list;
    OnClickListenerEditOrDelete onClickListenerEditOrDelete;
    int type;
    public ServiceListAdapter(Context context, List<FWBook.DataBean> list,int type) {
        this.context=context;
        this.list=list;
        this.type=type;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view=View.inflate(context, R.layout.service_listitem_select,null);
            holder = new ViewHolder();
            holder.addelete = (TextView) view.findViewById(R.id.adservice_delete);
            holder.adedit = (TextView) view.findViewById(R.id.adservicer_edit);
            holder.contenttext = (TextView) view.findViewById(R.id.adservice_contenttext);
            holder.listimg = (ImageView) view.findViewById(R.id.adservice_listimg);
            holder.listname = (TextView) view.findViewById(R.id.adservice_listname);
            holder.listprice = (TextView) view.findViewById(R.id.adservice_listprice);
            holder.listpeople = (TextView) view.findViewById(R.id.adservice_listpeople);
            holder.pinglun = (ImageView) view.findViewById(R.id.adservice_pinglun1);
            view.setTag(holder);
        }else {
            view=convertView;
            holder = (ViewHolder) view.getTag();
        }
        FWBook.DataBean dataBean = list.get(position);
        String name = dataBean.getName();
        int amount = dataBean.getAmount();
        String intro = dataBean.getIntro();
        int volume = dataBean.getVolume();

         holder.contenttext.setText(intro);
        holder.listpeople.setText(list.get(position).getVolume()+" 人付款");
        holder.listprice.setText(list.get(position).getAmount()+"元/单");
        holder.listname.setText(name);
        Picasso.with(context).load(InternetAddressUtis.IMG_URL+list.get(position).getServiceAvatar()).error(R.mipmap.morentouxiang).into(holder.listimg);

        holder.addelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerDelete(position);

                }
            }
        });
        holder.adedit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerEdit(position);

                }
            }
        });
        if (type==1){
            holder.addelete.setText("删除");
            holder.adedit.setText("编辑");

        }else {
            holder.addelete.setText("彻底删除");
            holder.adedit.setText("待上架");
        }

        return view;
    }

    class ViewHolder{
        TextView addelete,adedit,listname,listprice,contenttext,listpeople;
        ImageView listimg,pinglun;
    }
    public interface OnClickListenerEditOrDelete{
        void OnClickListenerEdit(int position);
        void OnClickListenerDelete(int position);
    }

    public void setOnClickListenerEditOrDelete(OnClickListenerEditOrDelete onClickListenerEditOrDelete1){
        this.onClickListenerEditOrDelete=onClickListenerEditOrDelete1;
    }
}
